package com.fs.dao.Impl;

import com.fs.dao.ClassStudentDao;
import com.fs.pojo.ClassStudent;
import com.fs.utils.JDBCUtils;

import java.util.List;

public class ClassStudentDaoImpl implements ClassStudentDao {
    @Override
    public ClassStudent queryById(String id) {
        String sql = "select * from tb_class_student where id = ?";
        List<ClassStudent> classStudents = JDBCUtils.executeQurey(sql, ClassStudent.class, id);
        return classStudents == null ? null : classStudents.get(0);
    }

    @Override
    public List queryAll() {
        String sql = "select * from tb_class_student";
        return JDBCUtils.executeQurey(sql,ClassStudent.class);
    }

    @Override
    public int insert(ClassStudent obj) {
        String sql = "insert into tb_class_student (id,class_id, student_id,is_top) values (?,?,?,?)";
        return JDBCUtils.executeUpdate(sql,obj);
    }

    @Override
    public int deleteById(String id) {
        String sql = "delete from tb_class_student where id = ?";
        return JDBCUtils.executeUpdate(sql,id);
    }

    @Override
    public int update(ClassStudent obj) {
        String sql = JDBCUtils.parseUpdateSQL(obj,"tb_class_student");
        return JDBCUtils.executeUpdate(sql,obj);
    }

    @Override
    public List<ClassStudent> QueryAllByStudentId(String id) {
        String sql = "select * from tb_class_student where student_id = ?";

        return JDBCUtils.executeQurey(sql,ClassStudent.class,id);
    }

    @Override
    public int deleteByClassIdAndStudenID(String classId,String studentId) {
        String sql = "delete from tb_class_student where class_id = ? and student_id = ?";
        return JDBCUtils.executeUpdate(sql,classId,studentId);
    }


}
